#include "voltlabel.h"

VoltLabel::VoltLabel(QWidget *parent) : QWidget(parent)
{
}

void VoltLabel::paintEvent(QPaintEvent *)
{
  QImage imageBackground(":/volt_amp/volt_background");

  QPainter painter(this);
  painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
  painter.drawImage(rect(), imageBackground);

  //绘制电压
  painter.drawImage(42, 53, QImage(QString(":/volt_amp/%1").arg(voltValue / 100)));
  painter.drawImage(60, 53, QImage(QString(":/volt_amp/%1").arg(voltValue / 10 % 10)));
  painter.drawImage(78, 53, QImage(QString(":/volt_amp/%1").arg(voltValue % 10)));

  //绘制电流
  painter.drawImage(42, 88, QImage(QString(":/volt_amp/%1").arg(ampValue / 100)));
  painter.drawImage(60, 88, QImage(QString(":/volt_amp/%1").arg(ampValue / 10 % 10)));
  painter.drawImage(78, 88, QImage(QString(":/volt_amp/%1").arg(ampValue % 10)));
}

void VoltLabel::setVoltValue(const qint32 &value)
{
  voltValue = value;
}

void VoltLabel::setAmpValue(const qint32 &value)
{
  ampValue = value;
}
